import absSubAction from "../abssubcmdaction";
import globalConst from "../../../canvas/common/globalConst.js";
var global = globalConst.GlobalConst;
import {LGXEnums}  from "../../../canvas/common/sysenum";

import cmdenums from "../cmdenums";

class ArcDrawAction extends absSubAction.AbsSubAction {
    constructor() {
        super();
        this.mode = 2;
        this.preCMD = "";
        this.haveEnterMode = false;
        this.mainCMD = cmdenums.DrawCmdType.arc;
    }

    actCMD(type, val, mainctl) {
        console.log("ArcDrawAction act cmd ");
        let actRst = null;
        let nextTips = "";
        if (type == cmdenums.DrawCmdType.arc) {
            let toolKind = global.BaseUnitArc;
            toolKind = toolKind << 16;
            mainctl.setCMDTool(toolKind);
            nextTips = "请选择绘制模式。圆心半径角度式（1）;三点式（2）";
            let cmd = { type: 'a', value: "" };
            actRst = { cmdObj: cmd, nextTips, appendToPreCMD: "", finish: false };
        }
        else {
            if (this.preCMD == cmdenums.DrawCmdType.arc) {
                this.mode = parseInt(type);
                if (this.mode == 0) {
                    this.mode = 1;
                }

                let plotMode = LGXEnums.ArcPlotMode.CenterAngleMode;
                if (this.mode == 2) {
                    plotMode = LGXEnums.ArcPlotMode.Point3Mode;
                }
                mainctl.m_pEditINTF.setArcPlotMode(plotMode);

                if (this.mode == 1) {
                    nextTips = "输入或在图中鼠标左键点击确定圆心坐标:x,y";
                    let cmd = { type: 'sel_arc_plotmode', value: this.mode };
                    actRst = { cmdObj: cmd, nextTips, appendToPreCMD: "", finish: false };
                }
                else if (this.mode == 2) {
                    nextTips = "输入或在图中鼠标左键点击确定圆弧起点坐标:x,y";
                    let cmd = { type: 'sel_arc_plotmode', value: this.mode };
                    actRst = { cmdObj: cmd, nextTips, appendToPreCMD: "", finish: false };
                }
                this.haveEnterMode = true;
            }
            else {
                actRst = this.act2InPlottingCMD(type,mainctl);
            }
        }
        this.preCMD = type;
        return actRst;
    }

    actCanvasEvt(evt, mainctl) {
        let actRst = null;
        if (evt.eventKind == LGXEnums.LGXEventKind.FinishDraw) {
            let coordDecs = evt.wx.toFixed(2) + "," + evt.wy.toFixed(2);
            let cmd = new absSubAction.TCmd();
            cmd.type = 'draw_lmousedown';
            cmd.value = coordDecs;
            let appendToPreCMD = coordDecs;
            actRst = { cmdObj: cmd, nextTips: "", appendToPreCMD, finish: true };
        }
        else if (evt.mouseDownTime > 0) {
            let coordDecs = evt.wx.toFixed(2) + "," + evt.wy.toFixed(2);
            let cmd = new absSubAction.TCmd();
            cmd.type = 'draw_lmousedown';
            cmd.value = coordDecs;
            let appendToPreCMD = coordDecs;

            let appendToPreNextCMD = "";

            let nextTips = "";
            if (this.mode == 1) {
                if (evt.mouseDownTime == 1) {
                    if (this.haveEnterMode) {
                        nextTips = "输入第二个点坐标或在图中单击确定半径及起点角度:x,y,相对坐标使用:@x,y。输入半径使用:r+半径值（如:r20）。结束（e）";
                    }
                    else {
                        this.preCMD = "draw_lmousedown";
                        appendToPreCMD = "draw_lmousedown";
                        appendToPreNextCMD = "输入或在图中鼠标左键点击确定圆心坐标:x,y>"+coordDecs;
                        nextTips = "输入第二个点坐标或在图中单击确定半径及起点角度:x,y,相对坐标使用:@x,y。输入半径使用:r+半径值（如:r20）。结束（e）";
                    }
                }
                else if (evt.mouseDownTime == 2) {
                    nextTips = "输入角度值确定终止角度,使用当前位置直接回车结束（e）";
                }
            }
            else if (this.mode == 2) {
                if (evt.mouseDownTime == 1) {
                    this.preCMD = "draw_lmousedown";
                    nextTips = "输入或在图中单击确定第二个点坐标:x,y,相对坐标使用:@x,y";
                }
                else if (evt.mouseDownTime == 2) {
                    nextTips = "输入或在图中单击确定第三个点坐标:x,y,相对坐标使用:@x,y";
                }
            }

            
            actRst = { cmdObj: cmd, nextTips, appendToPreCMD ,appendToPreNextCMD};
        }
        return actRst;
    }
}

export default { ArcDrawAction }